package com.mentaleye.biz.impl;

import com.mentaleye.bean.StudentActivityBean;
import com.mentaleye.biz.StudentActivityBiz;
import com.mentaleye.enums.DictionaryEnums;
import com.mentaleye.service.StudentActivityService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentActivityBizImpl implements StudentActivityBiz {

    @Autowired
    private StudentActivityService studentActivityService;
    private static Logger logger = Logger.getLogger(StudentActivityBizImpl.class);

    public void getActivityByMap(CommonPage commonPage) {
        try {
            studentActivityService.queryStuActByPage(commonPage);
        } catch (Exception e) {
            logger.error("分页查询学生活动异常", e);
        }

    }

    public CommonResult editActivity(StudentActivityBean studentActivityBean) {
        CommonResult commonResult = new CommonResult();
        try {
            boolean boo = studentActivityBean.getActivityId() == null;
            if (boo) {
                studentActivityBean.setApprovalStatus(DictionaryEnums.UNCOMMOTTED.getCode());//初次保存  未提交状态
                commonResult = studentActivityService.addActivity(studentActivityBean);
            } else {
                if (studentActivityBean.getActivityContext() != null && !"".equals(studentActivityBean.getActivityContext())) {
                    studentActivityBean.setApprovalStatus(DictionaryEnums.COMPLETED.getCode());
                }else {
                    studentActivityBean.setApprovalStatus(DictionaryEnums.UNCOMMOTTED.getCode());
                }
                commonResult = studentActivityService.updatActivity(studentActivityBean);
            }
        } catch (Exception e) {
            logger.error("学生活动编辑异常", e);
        }
        return commonResult;
    }

    public CommonResult submitActivity(Integer activityId) {
        CommonResult commonResult = new CommonResult();
        try {
            StudentActivityBean studentActivity = new StudentActivityBean();
            studentActivity.setActivityId(activityId);
            studentActivity.setApprovalStatus(DictionaryEnums.PENDING_APPROVAL.getCode());
            commonResult = studentActivityService.updateStatusById(studentActivity);
        } catch (Exception e) {
            logger.error("学生活动提交异常", e);
        }
        return commonResult;
    }

    public StudentActivityBean getActivityById(Integer activityId) {
        StudentActivityBean bean = new StudentActivityBean();
        try {
            bean = studentActivityService.queryByActivityId(activityId);
        } catch (Exception e) {
            logger.error("通过活动编号获取活动异常", e);
        }
        return bean;
    }

    public CommonResult editActivitySelectiveById(StudentActivityBean studentActivityBean) {
        CommonResult commonResult = new CommonResult();
        try {
                commonResult = studentActivityService.updateByPrimaryKeySelectiveById(studentActivityBean);
        } catch (Exception e) {
            logger.error("照片编辑异常编辑异常", e);
        }
        return commonResult;
    }


}
